/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef RANKABSTRACT_H_
#define RANKABSTRACT_H_

#include "../EnumAbstract.h"

template<template<typename> class Rank, typename Int>
class RankAbstract : public EnumAbstract<Rank<Int>, Int> {
public:
	static const Int COUNT = 9;
	static const Rank<Int> R1();
	static const Rank<Int> R2();
	static const Rank<Int> R3();
	static const Rank<Int> R4();
	static const Rank<Int> R5();
	static const Rank<Int> R6();
	static const Rank<Int> R7();
	static const Rank<Int> R8();

	template<class Color>
	static const Rank<Int> last(const Color C) {
		return C.isWhite() ? Rank<Int>::R8() : Rank<Int>::R1();
	}

	template<class Color>
	static const Rank<Int> first(const Color C) {
		return C.isWhite() ? Rank<Int>::R1() : Rank<Int>::R8();
	}
public:
	static const Rank<Int> BEGIN() { return Rank<Int>::R1(); }
	static const Rank<Int> RBEGIN() { return Rank<Int>::R8(); }
public:

	std::string toStr() const {
		std::string ret;
		if      ( this->me_c() == Rank<Int>::R1() ) ret = "1";
		else if ( this->me_c() == Rank<Int>::R2() ) ret = "2";
		else if ( this->me_c() == Rank<Int>::R3() ) ret = "3";
		else if ( this->me_c() == Rank<Int>::R4() ) ret = "4";
		else if ( this->me_c() == Rank<Int>::R5() ) ret = "5";
		else if ( this->me_c() == Rank<Int>::R6() ) ret = "6";
		else if ( this->me_c() == Rank<Int>::R7() ) ret = "7";
		else if ( this->me_c() == Rank<Int>::R8() ) ret = "8";
		else                                        ret = "-";

		return ret;
	}

	void fromStr(const std::string str) {
		if      ( "1" == str ) this->me() = Rank<Int>::R1();
		else if ( "2" == str ) this->me() = Rank<Int>::R2();
		else if ( "3" == str ) this->me() = Rank<Int>::R3();
		else if ( "4" == str ) this->me() = Rank<Int>::R4();
		else if ( "5" == str ) this->me() = Rank<Int>::R5();
		else if ( "6" == str ) this->me() = Rank<Int>::R6();
		else if ( "7" == str ) this->me() = Rank<Int>::R7();
		else if ( "8" == str ) this->me() = Rank<Int>::R8();
		else                   this->me() = Rank<Int>::NIL();
	}
};

#endif /* RANKABSTRACT_H_ */
